package com.wis.traffic.post.util;

import org.apache.commons.io.IOUtils;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.Reader;

public abstract class PostUtil {
    private static SqlSessionFactory sqlSessionFactory;

    static{
        try{
            Reader reader = Resources.getResourceAsReader("mybatis-conf.xml");
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
            IOUtils.closeQuietly(reader);
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    //获取SqlSession
    public static SqlSession getSqlSession(){
        return sqlSessionFactory.openSession();
    }
    //获取SqlSessionFactory
    public static SqlSessionFactory getSessionFactory(){
        return sqlSessionFactory;
    }
}
